/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.IndexManager;

import BLL.Parameter_BLL;
import DTO.Parameter_DTO;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Mr.Sam
 */
public class ParameterManager extends javax.swing.JInternalFrame {

    /**
     * Creates new form ParamaterManager
     */
    TableParameter model=new TableParameter();
    Parameter_BLL parameter=new Parameter_BLL();
    String sql="select * from PARAMETER";
    public ParameterManager() throws Exception {
        initComponents();
        model.SetTable(Table);
        model.SetData(sql);
    }
    public void ReloadTable(String sql) throws Exception
    {
        model.RemoveData();
        model.SetData(sql);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TienGuiToiThieu = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        TienRutToiThieu = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        SoNgayRutToithieu = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        SoNgayBatDauTinhLai = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        SoTienMoSoToiThieu = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        Table = new org.jdesktop.swingx.JXTable();
        ThayDoiQuyDinh = new javax.swing.JButton();

        setTitle("Quản Lý Tham Số");

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Số tiền Gửi Tối Thiểu");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 50, -1, -1));

        TienGuiToiThieu.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TienGuiToiThieuKeyTyped(evt);
            }
        });
        jPanel1.add(TienGuiToiThieu, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 50, 172, -1));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel2.setText("Số Tiền Rút Tối Thiểu");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(439, 50, -1, -1));

        TienRutToiThieu.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TienRutToiThieuKeyTyped(evt);
            }
        });
        jPanel1.add(TienRutToiThieu, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 40, 172, -1));

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel3.setText("Số Ngày Có Thể Rút Tối Thiểu");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 88, -1, -1));

        SoNgayRutToithieu.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                SoNgayRutToithieuKeyTyped(evt);
            }
        });
        jPanel1.add(SoNgayRutToithieu, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 90, 172, -1));

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel4.setText("Số Ngày Chưa Tính Lãi Sau Khi Mở Tài Khoản");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(439, 88, -1, -1));

        SoNgayBatDauTinhLai.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                SoNgayBatDauTinhLaiKeyTyped(evt);
            }
        });
        jPanel1.add(SoNgayBatDauTinhLai, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 80, 172, -1));

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel5.setText("Số Tiền Mở Sổ Nhỏ Nhất");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 126, -1, -1));

        SoTienMoSoToiThieu.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                SoTienMoSoToiThieuKeyTyped(evt);
            }
        });
        jPanel1.add(SoTienMoSoToiThieu, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, 172, -1));

        Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        Table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(Table);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 202, 1000, 240));

        ThayDoiQuyDinh.setText("Thay Đổi Quy Định");
        ThayDoiQuyDinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ThayDoiQuyDinhActionPerformed(evt);
            }
        });
        jPanel1.add(ThayDoiQuyDinh, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 164, -1, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ThayDoiQuyDinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ThayDoiQuyDinhActionPerformed
        // TODO add your handling code here:
        Parameter_DTO info=new Parameter_DTO();
        info.setMinofDeposit(Integer.parseInt(TienGuiToiThieu.getText()));
        info.setMinOfWithdraw(Integer.parseInt(TienRutToiThieu.getText()));
        info.setMinOfDepositPeriod(Integer.parseInt(SoNgayRutToithieu.getText()));
        info.setInterestFreePeriod(Integer.parseInt(SoNgayBatDauTinhLai.getText()));
        info.setMinOfAccountBalance(Float.parseFloat(SoTienMoSoToiThieu.getText()));
        try {
            parameter.Update("{call Update_Parameter(?,?,?,?,?)}", info);
            JOptionPane.showMessageDialog(null, "Thay Đổi Thành Công?");
            ReloadTable(sql);
        } catch (Exception ex) {
            Logger.getLogger(ParameterManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ThayDoiQuyDinhActionPerformed

    private void TableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TableMouseClicked
        // TODO add your handling code here:
        int index=Table.getSelectedRow();
        TienGuiToiThieu.setText(Table.getValueAt(index, 0)+"");
        TienRutToiThieu.setText(Table.getValueAt(index, 1)+"");
        SoNgayRutToithieu.setText(Table.getValueAt(index, 2)+"");
        SoNgayBatDauTinhLai.setText(Table.getValueAt(index, 3)+"");
        SoTienMoSoToiThieu.setText(Table.getValueAt(index, 4)+"");
    }//GEN-LAST:event_TableMouseClicked

    private void TienGuiToiThieuKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TienGuiToiThieuKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((c < 48 || c > 57)) {
            evt.consume();
        }
    }//GEN-LAST:event_TienGuiToiThieuKeyTyped

    private void TienRutToiThieuKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TienRutToiThieuKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((c < 48 || c > 57)) {
            evt.consume();
        }
    }//GEN-LAST:event_TienRutToiThieuKeyTyped

    private void SoNgayRutToithieuKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_SoNgayRutToithieuKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((c < 48 || c > 57)) {
            evt.consume();
        }
    }//GEN-LAST:event_SoNgayRutToithieuKeyTyped

    private void SoNgayBatDauTinhLaiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_SoNgayBatDauTinhLaiKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((c < 48 || c > 57)) {
            evt.consume();
        }
    }//GEN-LAST:event_SoNgayBatDauTinhLaiKeyTyped

    private void SoTienMoSoToiThieuKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_SoTienMoSoToiThieuKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((c < 48 || c > 57)) {
            evt.consume();
        }
    }//GEN-LAST:event_SoTienMoSoToiThieuKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField SoNgayBatDauTinhLai;
    private javax.swing.JTextField SoNgayRutToithieu;
    private javax.swing.JTextField SoTienMoSoToiThieu;
    private org.jdesktop.swingx.JXTable Table;
    private javax.swing.JButton ThayDoiQuyDinh;
    private javax.swing.JTextField TienGuiToiThieu;
    private javax.swing.JTextField TienRutToiThieu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
